﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using JM.JCY.Common;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;

namespace JM.JCY.SharePointComponent.IncorruptArchives.IncorruptBasicInfo
{
    public partial class IncorruptBasicInfoUserControl : UserControl
    {
        string currentAccount = SPContext.Current.Web.CurrentUser.Name;
        string listName1 = JCYConstant.SharePointListName.IncorruptBasicInfoZCYWB;
        string listName2 = JCYConstant.SharePointListName.IncorruptBasicInfoZCZHB;
        string listName3 = JCYConstant.SharePointListName.IncorruptBasicInfo3J;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPWeb web = SPContext.Current.Web;
                SPList list1 = web.Lists[listName1];
                SPList list2 = web.Lists[listName2];
                SPList list3 = web.Lists[listName3];
                lvList1.ListId = list1.ID.ToString();
                lvList2.ListId = list2.ID.ToString();
                lvList3.ListId = list3.ID.ToString();

                lvList1.ViewId = list1.Views["MyView"].ID.ToString();
                lvList2.ViewId = list2.Views["MyView"].ID.ToString();
                lvList3.ViewId = list3.Views["MyView"].ID.ToString();

                using (UserManagementProxy userProxy = new UserManagementProxy())
                {
                    int userId = 0;
                    DataSetUserManagement.T_UserInfoDataTable userDT = userProxy.GetUser(0, currentAccount);
                    if (userDT.Rows.Count > 0)
                        userId = userDT[0].ID;

                    DepartmentTitleDataSet.T_DeptTitleDataTable dt = userProxy.GetDeptTitleByUserId(userId);
                    foreach (DepartmentTitleDataSet.T_DeptTitleRow dr in dt.Rows)
	                {
		                if (dr.JobTitle.Contains("纪检组长") || dr.JobTitle.Contains("检察长"))
                        {
                            lvList1.ViewId = list1.Views["All"].ID.ToString();
                            lvList2.ViewId = list2.Views["All"].ID.ToString();
                            lvList3.ViewId = list3.Views["All"].ID.ToString();
                        }
	                }
                   
                  
                }

            

 
                string onclick1 = string.Format("javascript:NewItem2(event, '{0}');javascript:return false;", list1.DefaultNewFormUrl);
                this.linkCreate1.Attributes.Add("onclick", onclick1);

              
                string onclick2 = string.Format("javascript:NewItem2(event, '{0}');javascript:return false;", list2.DefaultNewFormUrl);
                this.linkCreate2.Attributes.Add("onclick", onclick2);

             
                string onclick3 = string.Format("javascript:NewItem2(event, '{0}');javascript:return false;", list3.DefaultNewFormUrl);
                this.linkCreate3.Attributes.Add("onclick", onclick3);


            }
        }
    }
}
